﻿namespace FiftyOne.Foundation.Mobile.Detection.Wurfl.Handlers
{
    using FiftyOne.Foundation.Mobile.Detection.Wurfl.Matchers;
    using FiftyOne.Foundation.Mobile.Detection.Wurfl.Matchers.EditDistance;
    using System;

    internal class SamsungHandler : RegexSegmentHandler
    {
        private const byte EXTRA_CONFIDENCE = 1;
        private static readonly string[] PATTERNS = new string[] { "(?i)(?:(?<=samsung|SEC-)[^/]+)", @"(?i)(?:(?<=samsung|SEC-[^/]+/)[^\s]+)" };

        internal SamsungHandler() : base(PATTERNS, new int[] { 100, 1 })
        {
        }

        protected internal override bool CanHandle(string userAgent)
        {
            return (((userAgent.IndexOf("samsung", StringComparison.InvariantCultureIgnoreCase) > -1) || userAgent.StartsWith("SEC-")) && base.CanHandle(userAgent));
        }

        protected internal override FiftyOne.Foundation.Mobile.Detection.Wurfl.Matchers.Results Match(string userAgent)
        {
            FiftyOne.Foundation.Mobile.Detection.Wurfl.Matchers.Results results = base.Match(userAgent);
            if ((results == null) || (results.Count == 0))
            {
                results = FiftyOne.Foundation.Mobile.Detection.Wurfl.Matchers.EditDistance.Matcher.Match(userAgent, this);
            }
            return results;
        }

        internal override byte Confidence
        {
            get
            {
                return (byte) (base.Confidence + 1);
            }
        }
    }
}

